package com.luyi.sensor.controller;

import com.luyi.sensor.config.Result;
import com.luyi.sensor.config.SqlVo;
import com.luyi.sensor.dao.sensor.SensorBootMapperImpl;
import com.luyi.sensor.dao.sensorRecordFeature.SensorRecordFeatureMapper;
import com.luyi.sensor.dao.sensorRecordFeature.SensorRecordFeatureMapperImpl;
import com.luyi.sensor.entity.Sensor;
import com.luyi.sensor.entity.SensorRecordFeature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * SensorController 控制层
 * author: luyi
 * time: 2022/1/12 16:42
 */
@RestController
@RequestMapping(value = "/sensor")
public class SensorController {
    @Autowired
    SensorBootMapperImpl sensorBootMapperImpl = new SensorBootMapperImpl();
    @Autowired
    SensorRecordFeatureMapperImpl sensorRecordFeatureMapperImpl = new SensorRecordFeatureMapperImpl();
    SqlVo sql = null;//实例化一条SQl对象

    /**
     * 查询所有
     * @return
     */


    /**
     * 根据时间查询
     *
     * @param pageNum 页号
     * @param pageSize 单个页面大小
     * @param time 查询限定时间（天）
     * @return
     */
//    @RequestMapping("/searchByTime")
//    public Result<?> selectAllArticle(@RequestParam(defaultValue = "1") Integer pageNum,
//                                      @RequestParam(defaultValue = "14") Integer pageSize,
//                                      @RequestParam(defaultValue = "7") Integer time){
//        return sensorBootMapperImpl.searchByTime(pageNum, pageSize, time);
//    }

    /**
     * 插入单条传感器数据
     * @param sensor
     * @return
     */
    @RequestMapping("/addSensor")
    public Result addSensor(@RequestBody @Valid Sensor sensor){
        return sensorBootMapperImpl.addSensor(sensor);
    }

    /**
     * 执行自定义的SQl
     * @param sensor
     * @return
     */
//    @RequestMapping("/addSensor")
//    public Result addSensor(@RequestParam String sqlString){
//
//        sql = new SqlVo(sqlString);
////        sql;
//        return sensorBootMapperImpl.addSensor(sensor);
//    }


    /**
     * 统计概览
     * 分页查询所有的传感器信息
     */
    @RequestMapping("/getAllSensor")
    public Result<?> getAllSensor(@RequestParam(defaultValue = "1") Integer pageNum,
                                  @RequestParam(defaultValue = "14") Integer pageSize){
        return sensorBootMapperImpl.getAllSensor(pageNum, pageSize);
    }

    /**
     * 查询传感器信息
     * 分页查询所有的传感器信息
     * TODO: Integer还是long
     */
    @RequestMapping("/getSensorById")
    public Result<?> getSensorById(@RequestParam int id){
        System.out.println(id);
        return sensorBootMapperImpl.getSensorById(id);
    }

    /**
     * 查询传感器de最新参数
     * 分页查询所有的传感器信息
     * TODO: Integer还是long
     */
//    @RequestMapping("/getSensorRecordById")
//    public Result<?> getSensorRecordById(@RequestParam int id){
//        System.out.println(id);
//        return sensorBootMapperImpl.getSensorRecordById(id);
//    }

    /**
     * 查询传感器de最新参数
     * 分页查询所有的传感器信息
     * TODO: Integer还是long
     */
    @RequestMapping("/getSensorRecordFeature")
    public Result<?> getSensorRecordFeature(){
        return sensorRecordFeatureMapperImpl.getSensorRecordFeature();
    }
}
